package com.lkd.controller;


import com.lkd.entity.VmType;
import com.lkd.service.VmTypeService;
import com.lkd.vo.PageBean;
import com.lkd.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 售货机类型表 前端控制器
 * </p>
 *
 * @author 聂德祥
 * @since 2024-08-19
 */
@RestController
public class VmTypeController {
    @Autowired
    private VmTypeService vmTypeService;

    @GetMapping("/api/vm-service/vmType/search")
    public Result getList(String name, @RequestParam(defaultValue = "1") Integer pageIndex,@RequestParam(defaultValue = "10") Integer pageSize){
        PageBean<VmType> pageBean = vmTypeService.search(name,pageIndex,pageSize);
        return Result.success(pageBean);
    }
    @PostMapping("/api/vm-service/vmType")
    public Result add(@RequestBody VmType vmType){
        vmTypeService.save(vmType);
        return Result.success();
    }
    // 修改售货机类型
    @PutMapping("/api/vm-service/vmType")
    public Result update(@RequestBody VmType vmType){
        vmTypeService.updateById(vmType);
        return Result.success();
    }
    // 删除售货机类型
    @DeleteMapping("/api/vm-service/vmType/{typeid}")
    public Result delete(@PathVariable Integer typeid){
        // TODO 删除售货机类型之前，判断该类型是否已经绑定了售货机
        vmTypeService.removeById(typeid);
        return Result.success();
    }

}
